package cn.tedu.baking.controller;

import cn.tedu.baking.commom.response.JsonResult;
import cn.tedu.baking.pojo.dto.ContentDTO;
import cn.tedu.baking.pojo.vo.*;
import cn.tedu.baking.service.impl.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("v1/contents")
public class ContentController {
    @Autowired
    ContentService service;
    @PostMapping("add-new")
    public JsonResult addNew(ContentDTO contentDTO){
        System.out.println("contentDTO = " + contentDTO);
        service.addNew(contentDTO);
        return JsonResult.ok();
    }
    @GetMapping("{type}/{userId}/management")
    public JsonResult listForManagment(@PathVariable Long type,@PathVariable Long userId){
        List<ContentManagmentVO> list=service.listForManagment(type,userId);
        return JsonResult.ok(list);
    }
    @PostMapping("{id}/delete")
    public JsonResult delete(@PathVariable Long id){
        service.deleteById(id);
        return JsonResult.ok();
    }

    @GetMapping("{id}/update")
    public JsonResult updateByid(@PathVariable Long id){
        ContentUpdateVO contentUpdateVO=service.updateById(id);
        return JsonResult.ok(contentUpdateVO);
    }

    @GetMapping("{type}/{categoryId}/index")
    public JsonResult listForIndex(@PathVariable Long type,@PathVariable Long categoryId){
        List<ContentIndexVO> list=service.listForIndex(type,categoryId);
        return JsonResult.ok(list);
    }
    @GetMapping("{id}/detail")
    public JsonResult detail(@PathVariable Long id){
        ContentDetailVO contentDetailVO= service.detailByid(id);
        return JsonResult.ok(contentDetailVO);
    }
    @GetMapping("{userId}/{id}/other")
    public JsonResult other(@PathVariable Long userId,@PathVariable Long id){
        List<ContentSimpleVO> list= service.selectOtherByUserId(userId,id);
        return JsonResult.ok(list);
    }
    @GetMapping("{type}/list")
    public JsonResult listByType(@PathVariable Long type){
        List<ContentIndexVO> list=service.listByType(type);
        return JsonResult.ok(list);
    }
    @GetMapping("{wd}/search")
    public JsonResult searchByWd(@PathVariable String wd){
        List<ContentIndexVO> search=service.searchByWd(wd);
        return JsonResult.ok(search);
    }

    @GetMapping("list/admin")
    public JsonResult loadUser(){
        List<ContentAdminVO> list=service.selectloadUser();
        return JsonResult.ok(list);
    }
}
